using System;
using CfgTable;
using IQIGame.Onigao.GamePlay;
using NetProtocol.POD;
using System.Collections.Generic;

namespace IQIGame.Onigao.Logic
{
    public class LogicHeroData
    {
        public long id { get; }
        public CfgHero cfg { get; }
        public int cid => cfg.Id;
        public int skinCid { get; private set; }
        public int awakenLevel { get; private set; }
        public int level { get; private set; }
        public int exp { get; private set; }
        public int star { get; private set; }

        public Dictionary<int, long> equips { get; private set; }
        /** 英雄自带的技能 */
        public Dictionary<int, int> skills { get; private set; }
        /** 装备等获得的技能 */
        public Dictionary<int, int> extraSkills { get; private set; }
        /** 英雄身上的所有技能 */
        public Dictionary<int, int> allSkills { get; } = new Dictionary<int, int>();

        /** 属性 */
        public int[] attrs { get; private set; }
        /** 装备的宠物 */
        public long petId { get; private set; }
        
        public LogicHeroData(HeroPOD heroPOD)
        {
            id = heroPOD.id;
            cfg = TableCenter.hero.Get(heroPOD.cid);
            SyncData(heroPOD);
        }

        public void SyncData(HeroPOD heroPOD)
        {
            if (this.id != heroPOD.id)
            {
                throw new ArgumentException();
            }
            skinCid = heroPOD.skinCid;
            awakenLevel = heroPOD.awakenLevel;
            level = heroPOD.level;
            exp = heroPOD.exp;
            star = heroPOD.star;

            equips = heroPOD.equips;
            skills = heroPOD.skills;
            extraSkills = heroPOD.extraSkills ?? new Dictionary<int, int>();
            
            allSkills.Clear();
            allSkills.AddRange(skills);
            allSkills.AddRange(extraSkills);
            
            attrs = heroPOD.attrs ?? new int[TableCenter.attribute.DataList.Count + 1];
            petId = heroPOD.petId;
        }
    }
}